<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>Zookeeper Processor | flyingzc's blog</title><meta name="author" content="flyingzc"><meta name="copyright" content="flyingzc"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="processors PrepRequestProcessor通常是请求处理链的第一个处理器.识别客户端请求是否是事务请求.对于事务请求,做预处理,诸如 创建请求事务头,事务体,会话检查,ACL检查 和 版本检查 等.  ProposalRequestProcessorleader 服务器的事务投票处理器,也是 leader 服务器事务处理流程的发起者.对于 非事务请求,它会直接将请求流转到 Co">
<meta property="og:type" content="article">
<meta property="og:title" content="Zookeeper Processor">
<meta property="og:url" content="https://flyingzc.github.io/articles/zk/zk05_processor.html">
<meta property="og:site_name" content="flyingzc&#39;s blog">
<meta property="og:description" content="processors PrepRequestProcessor通常是请求处理链的第一个处理器.识别客户端请求是否是事务请求.对于事务请求,做预处理,诸如 创建请求事务头,事务体,会话检查,ACL检查 和 版本检查 等.  ProposalRequestProcessorleader 服务器的事务投票处理器,也是 leader 服务器事务处理流程的发起者.对于 非事务请求,它会直接将请求流转到 Co">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://flyingzc.github.io/images/zc-icon.jpeg">
<meta property="article:published_time" content="2019-03-07T16:00:00.000Z">
<meta property="article:modified_time" content="2025-01-21T01:51:41.216Z">
<meta property="article:author" content="flyingzc">
<meta property="article:tag" content="Zookeeper">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://flyingzc.github.io/images/zc-icon.jpeg"><script type="application/ld+json">{
  "@context": "https://schema.org",
  "@type": "BlogPosting",
  "headline": "Zookeeper Processor",
  "url": "https://flyingzc.github.io/articles/zk/zk05_processor.html",
  "image": "https://flyingzc.github.io/images/zc-icon.jpeg",
  "datePublished": "2019-03-07T16:00:00.000Z",
  "dateModified": "2025-01-21T01:51:41.216Z",
  "author": [
    {
      "@type": "Person",
      "name": "flyingzc",
      "url": "https://flyingzc.github.io/"
    }
  ]
}</script><link rel="shortcut icon" href="/images/zc-icon.jpeg"><link rel="canonical" href="https://flyingzc.github.io/articles/zk/zk05_processor.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><meta name="google-site-verification" content="DentpX3LnP_WNgEeFnNIcTZZky-Bby-zL-uI_9GqTAw"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css"><script>
    (() => {
      
    const saveToLocal = {
      set: (key, value, ttl) => {
        if (!ttl) return
        const expiry = Date.now() + ttl * 86400000
        localStorage.setItem(key, JSON.stringify({ value, expiry }))
      },
      get: key => {
        const itemStr = localStorage.getItem(key)
        if (!itemStr) return undefined
        const { value, expiry } = JSON.parse(itemStr)
        if (Date.now() > expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return value
      }
    }

    window.btf = {
      saveToLocal,
      getScript: (url, attr = {}) => new Promise((resolve, reject) => {
        const script = document.createElement('script')
        script.src = url
        script.async = true
        Object.entries(attr).forEach(([key, val]) => script.setAttribute(key, val))
        script.onload = script.onreadystatechange = () => {
          if (!script.readyState || /loaded|complete/.test(script.readyState)) resolve()
        }
        script.onerror = reject
        document.head.appendChild(script)
      }),
      getCSS: (url, id) => new Promise((resolve, reject) => {
        const link = document.createElement('link')
        link.rel = 'stylesheet'
        link.href = url
        if (id) link.id = id
        link.onload = link.onreadystatechange = () => {
          if (!link.readyState || /loaded|complete/.test(link.readyState)) resolve()
        }
        link.onerror = reject
        document.head.appendChild(link)
      }),
      addGlobalFn: (key, fn, name = false, parent = window) => {
        if (!false && key.startsWith('pjax')) return
        const globalFn = parent.globalFn || {}
        globalFn[key] = globalFn[key] || {}
        globalFn[key][name || Object.keys(globalFn[key]).length] = fn
        parent.globalFn = globalFn
      }
    }
  
      
      const activateDarkMode = () => {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      const activateLightMode = () => {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }

      btf.activateDarkMode = activateDarkMode
      btf.activateLightMode = activateLightMode

      const theme = saveToLocal.get('theme')
    
          theme === 'dark' ? activateDarkMode() : theme === 'light' ? activateLightMode() : null
        
      
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        document.documentElement.classList.toggle('hide-aside', asideStatus === 'hide')
      }
    
      
    const detectApple = () => {
      if (/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)) {
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
  
    })()
  </script><script async="async" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><script>(adsbygoogle = window.adsbygoogle || []).push({
  google_ad_client: '',
  enable_page_level_ads: 'true'
});</script><script>const GLOBAL_CONFIG = {
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  highlight: {"plugin":"highlight.js","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false,"highlightFullpage":false,"highlightMacStyle":false},
  copy: {
    success: '复制成功',
    error: '复制失败',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'null',
  Snackbar: undefined,
  infinitegrid: {
    js: 'https://cdn.jsdelivr.net/npm/@egjs/infinitegrid/dist/infinitegrid.min.js',
    buttonText: '加载更多'
  },
  isPhotoFigcaption: false,
  islazyloadPlugin: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Zookeeper Processor',
  isHighlightShrink: false,
  isToc: true,
  pageType: 'post'
}</script><link rel="stylesheet" href="/self/github-dark.css"><meta name="generator" content="Hexo 7.0.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img text-center"><img src="/images/zc-icon.jpeg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data text-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">84</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">36</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">29</div></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header"><nav id="nav"><span id="blog-info"><a class="nav-site-title" href="/"><span class="site-name">flyingzc's blog</span></a><a class="nav-page-title" href="/"><span class="site-name">Zookeeper Processor</span></a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div></div><div id="toggle-menu"><span class="site-page"><i class="fas fa-bars fa-fw"></i></span></div></div></nav><div id="post-info"><h1 class="post-title">Zookeeper Processor</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2019-03-07T16:00:00.000Z" title="发表于 2019-03-08 00:00:00">2019-03-08</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2025-01-21T01:51:41.216Z" title="更新于 2025-01-21 09:51:41">2025-01-21</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/Zookeeper/">Zookeeper</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title=""><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">浏览量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="container post-content" id="article-container"><h3 id="processors"><a href="#processors" class="headerlink" title="processors"></a>processors</h3><ul>
<li><p>PrepRequestProcessor<br>通常是请求处理链的第一个处理器.<br>识别客户端请求是否是事务请求.对于事务请求,做预处理,诸如 创建请求事务头,事务体,会话检查,ACL检查 和 版本检查 等.</p>
</li>
<li><p>ProposalRequestProcessor<br>leader 服务器的<code>事务投票处理器</code>,也是 leader 服务器事务处理流程的发起者.<br>对于 非事务请求,它会直接将请求流转到 CommitProcessor 处理器,不再做其他处理.<br>对于 事务请求,除了将请求交给CommitProcessor处理器外,还会根据请求类型创建对应的 Proposal 提议,并 发给所有 Follower 来发起一次集群内的事务投票.它还会将事务请求交给 SyncRequestProcessor 进行事务日志的记录.</p>
</li>
<li><p>SyncRequestProcessor<br>事务日志记录处理器,将事务请求记录到事务日志文件中,同时还会触发zk进行数据快照.<br>发送Sync请求的处理器.将请求记录到磁盘.它批量处理有效执行io的请求.在将日志同步到磁盘之前,请求不会传递到下一个 Processor.<br>维护了一个处理请求的队列,其用于存放请求;<br>维护了一个处理快照的线程,用于处理快照;<br>维护了一个等待被刷新到磁盘的请求队列.<br>将事务性请求刷新到磁盘,并且对请求进行快照处理.</p>
</li>
<li><p>AckRequestProcessor<br>leader 独有的处理器,它负责在 SyncRequestProcessor 处理器完成事务日志记录后,向 Proposal 的投票收集器发送 ACK 反馈,以通知投票收集器当前服务器已经完成了对该 Proposal 的事务日志记录.<br>将前一阶段的请求作为 ACK 转发给 Leader.</p>
</li>
<li><p>CommitProcessor<br>事务提交处理器.<br>对于非事务请求,该处理器直接将其交给下一个处理器进行处理.<br>对于事务请求,它会等待集群内 针对 Proposal 的投票,直到该 Proposal 可被提交.</p>
</li>
<li><p>ToBeAppliedRequestProcessor<br>维护 toBeApplied 队列,专门存储那些已经被 CommitProcessor 处理过的可被提交的 Proposal.<br>它将这些请求逐个交付给 FinalRequestProcessor 处理器进行处理,等待 FinalRequestProcessor 处理器处理完后,再将其从toBeApplied 队列中移除.<br>下个处理器必须是 FinalRequestProcessor 并且 FinalRequestProcessor 必须同步处理请求.</p>
</li>
<li><p>FinalRequestProcessor<br>通常是请求处理链的最后一个处理器.<br>创建客户端请求的响应;针对事务请求,它还会负责<code>将事务应用到内存数据库</code>中.</p>
</li>
<li><p>FollowerRequestProcessor<br>它是 follower 的第一个请求处理器.用于识别当前请求是否是事务请求.<br>若是事务请求,转发给 leader 服务器.leader 在收到这个事务请求后,就会将其提交到请求处理器链,按照正常事务请求进行处理.</p>
</li>
<li><p>ObserverRequestProcessor<br>同 FollowerRequestProcessor 一样,将事务请求转发给 Leader.</p>
</li>
<li><p>SendAckRequestProcessor<br>follower 独有,发送 ACK 请求的处理器.<br>在 follower 完成事务日志记录后,会向 leader 服务器发送 ACK 消息表面自身完成了事务日志的记录工作.<br>它和 leader 的 AckRequestProcessor 的区别:<br>AckRequestProcessor 处理器和 leader 服务器在同一个服务器上,它的 ACK 反馈仅仅是一个本地操作.<br>SendAckRequestProcessor 处理器在 follower 服务器上,需要通过 ACK 消息向 leader 服务器进行反馈.</p>
</li>
</ul>
<h3 id="processor链对事务请求的处理"><a href="#processor链对事务请求的处理" class="headerlink" title="processor链对事务请求的处理"></a>processor链对事务请求的处理</h3><h4 id="PrepRequestProcessor"><a href="#PrepRequestProcessor" class="headerlink" title="PrepRequestProcessor"></a>PrepRequestProcessor</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs plaintext">- PrepRequestProcessor <br>    - 作用<br>        - 通常是请求处理链的第一个处理器。 <br>        - 识别客户端请求是否是事务请求. 对于事务请求,做预处理,诸如 创建请求事务头,事务体,会话检查,ACL检查 和 版本检查 等.<br>    - run()逻辑<br>        - pRequest(request);中 判断请求类型. 对于事务请求,不同类型请求对应不同操作. 比如create请求<br>        - CreateRequest createRequest = new CreateRequest(); pRequest2Txn(request.type, zks.getNextZxid(), request, createRequest, true);<br>            - pRequest2Txn()中 new TxnHeader() 创建请求事务头,后续的processors都是基于该请求头来识别当前请求是否是事务请求<br>            - zks.sessionTracker.checkSession(request.sessionId, request.getOwner());// session检查<br>            - 请求数据反序列化到CreateRequest对象中<br>            - 添加到zks.outstandingChanges中 // TODO finalRequestProcessor中会用到 addChangeRecord(parentRecord); addChangeRecord(new ChangeRecord(request.hdr.getZxid(), path, s, 0, listACL));<br>        - nextProcessor.processRequest(request); 交由下个processor处理<br>            - ProposalRequestProcessor.processRequest() // 参见ProposalRequestProcessor.processRequest()逻辑<br></code></pre></td></tr></table></figure>

<h4 id="ProposalRequestProcessor"><a href="#ProposalRequestProcessor" class="headerlink" title="ProposalRequestProcessor"></a>ProposalRequestProcessor</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><code class="hljs plaintext">- ProposalRequestProcessor<br>    - 作用<br>        - leader服务器的`事务投票处理器`,也是leader服务器事务处理流程的发起者. <br>        - 对于 非事务请求,它会直接将请求流转到CommitProcessor处理器,不再做其他处理. <br>        - 对于 事务请求,除了将请求交给CommitProcessor处理器外,还会根据请求类型创建对应的Proposal提议,并发给所有Follower来发起一次集群内的事务投票.它还会将事务请求交给SyncRequestProcessor进行事务日志的记录.<br><br>    - ProposalRequestProcessor.processRequest()中<br>        - nextProcessor.processRequest(request); 1.将请求交给下个处理器进行处理,下个处理器是commitProcessor,走COMMIT流程<br>            - commitProcessor.processRequest()中 queuedRequests.add(request); 将请求 添加到 请求队列<br>                - leader的commitProcessor处理<br>        - 若是事务请求<br>            - zks.getLeader().propose(request); 2.若是事务请求,发proposal包,发起PROPOSAL流程<br>                - leader.propose()中 outstandingProposals.put(lastProposed, p); 将事务请求放入outstandingProposals,它用于保存 zxid 和 proposal的映射<br>                - 发送Leader.PROPOSAL包  sendPacket(pp);<br>                    - leader.sendPacket()中 遍历所有LearnerHandler,依次调用,将proposal包存入待发送队列 f.queuePacket(qp);<br>                        - learnerHandler.queuePacket()中 queuedPackets.add(p) 将包存入队列<br>                            - learnerHandler线程<br>                                - learnerHandler.run()里 512行 新启一个线程 发送queuedPackets队列中的packets<br>                                    -  sendPackets();// 发送queuedPackets队列中的packets  if (p.getType() == Leader.PROPOSAL) &#123;    syncLimitCheck.updateProposal(p.getZxid(), System.nanoTime()); &#125;<br>                                    - oa.writeRecord(p, &quot;packet&quot;); 发送packet<br>                                        - Follower.processPacket()接收该Proposal包<br>                                            - Follower.processPacket()中<br>                                            - 反序列化请求数据<br>                                            - fzk.logRequest(hdr, txn);<br>                                                - FollowerZookeeperServer.logRequest()中 pendingTxns.add(request);请求入pendingTxns队列 // TODO 这个入队后面干嘛了<br>                                                - syncProcessor.processRequest(request);<br>                                                    - SyncRequestProcessor.processRequest()中 queuedRequests.add(request); 请求入队列<br>                                                        - follower将poposal中的请求持久化 // 后续见SyncRequestProcessor.run()逻辑<br></code></pre></td></tr></table></figure>

<h4 id="syncProcessor"><a href="#syncProcessor" class="headerlink" title="syncProcessor"></a>syncProcessor</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs plaintext">- syncProcessor.processRequest(request); 3.若是事务请求,交给 syncProcessor处理器记录事务日志,走SYNC流程<br>    - 这里是leader服务器进行事务持久化操作, follower服务器会通过上面2中的proposal流程最终触发follower自己的事务持久化操作 即事务持久化在所有follower和leader上都会进行<br>        - 事务持久化完成后会发ack给leader<br></code></pre></td></tr></table></figure>

<h4 id="SyncRequestProcessor"><a href="#SyncRequestProcessor" class="headerlink" title="SyncRequestProcessor"></a>SyncRequestProcessor</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><code class="hljs plaintext">- SyncRequestProcessor<br>    - 作用<br>        - 事务日志记录处理器, 将事务请求记录到事务日志文件中,同时还会触发zk进行数据快照.<br>        - 发送Sync请求的处理器。将请求记录到磁盘。它批量处理有效执行io的请求。在将日志同步到磁盘之前，请求不会传递到下一个RequestProcessor. <br>    - 成员变量<br>        - 维护了一个处理请求的队列queuedRequests，其用于存放请求<br>        - 维护了一个处理快照的线程 snapInProcess，用于处理快照<br>        - 维护了一个等待被刷新到磁盘的请求队列 toFlush <br><br>    - SyncRequestProcessor.processRequest()逻辑<br>        - queuedRequests.add(request); 事务请求入队列 private final LinkedBlockingQueue&lt;Request&gt; queuedRequests =         new LinkedBlockingQueue&lt;Request&gt;();// 请求队列<br><br>    - SyncRequestProcessor.run()逻辑<br>        - 初始化事务日志记录计数logCount,用于判断记录 n次事务日志后 是否需要进行 snapshot<br>        - 初始化设置滚动日志的随机数randRoll,该随机数用于防止所有servers在同一时刻进行snapshot操作<br>        - while循环<br>            - si = queuedRequests.poll(); 从队列中取出请求.<br>                - 若请求队列中的请求取完了,刷盘<br>                    - flush(toFlush);<br>                        - SyncRequestProcessor.flush()中 zks.getZKDatabase().commit();刷盘<br>                        - 刷盘结束后发ack,循环取出所有toFlush的nextProcessor. 并调用nextProcessor.processRequest()方法<br>                            - 1.leader调AckRequestProcessor,省去通信了 AckRequestProcessor.processRequest()中 leader.processAck(self.getId(), request.zxid, null);// ack给leader<br>                                - // 参见AckRequestProcessor.processRequest()逻辑<br>                            - 2.follower调SendAckRequestProcessor<br>                                - // 参见SendAckRequestProcessor逻辑<br>                - 若取出来的请求不为空<br>                    - (zks.getZKDatabase().append(si))  将请求添加至事务日志文件<br>                        - ZKDatabase.append()中 return this.snapLog.append(si);<br>                            - FileTxnSnapLog.append()中 return txnLog.append(si.hdr, si.txn);<br>                                - FileTxnLog.append()中 logStream.flush(); // 刷新到磁盘 返回true<br>                    - 如果事务日志记录次数达到了snapCount / 2 + randRoll次,新起线程进行snapshot操作,并重置logCount计数<br>                    - toFlush.add(si); 将请求添加至 toFlush队列<br>                    - toFlush队列大小 大于1000，直接刷新到磁盘<br></code></pre></td></tr></table></figure>

<h4 id="AckRequestProcessor"><a href="#AckRequestProcessor" class="headerlink" title="AckRequestProcessor"></a>AckRequestProcessor</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs plaintext">- AckRequestProcessor<br>    - 作用<br>        - leader独有的处理器,它负责在SyncRequestProcessor处理器完成事务日志记录后,向Proposal的投票收集器发送ACK反馈,以通知投票收集器当前服务器已经完成了对该Proposal的事务日志记录.<br><br>    - AckRequestProcessor.processRequest()逻辑<br>        - 1.leader调AckRequestProcessor,省去通信了 AckRequestProcessor.processRequest()中 leader.processAck(self.getId(), request.zxid, null);// ack给leader<br></code></pre></td></tr></table></figure>

<h4 id="SendAckRequestProcessor"><a href="#SendAckRequestProcessor" class="headerlink" title="SendAckRequestProcessor"></a>SendAckRequestProcessor</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><code class="hljs plaintext">- SendAckRequestProcessor<br>    - 作用<br>        - follower使用,用于follower将proposal中的request持久化后发ack给leader<br><br>    - SendAckRequestProcessor.processRequest()逻辑<br>        - SendAckRequestProcessor.processRequest()中 创建Leader.ACK包并发送 learner.writePacket(qp, false);<br>            - LearnerHandler线程<br>                - LearnerHandler.run()中 当Follower收到PROPOSAL并写到磁盘后会发送ACK给Leader case Leader.ACK:  leader.processAck(this.sid, qp.getZxid(), sock.getLocalSocketAddress());<br>                    - leader.processAck()中  处理ack包<br>                    - 1.根据zxid取出proposal Proposal p = outstandingProposals.get(zxid);<br>                    - p.ackSet.add(sid); 2.保存follower发来的ack的sid到该proposal对象中<br>                    - 判断self.getQuorumVerifier().containsQuorum(p.ackSet) 3.判断当接收到的对于 proposal包的ack是否超过一半<br>                        - QuorumMaj.containsQuorum()中 验证所给集合大小是否超过半数 return (set.size() &gt; half);<br>                    - 4.若此处leader接收到的对于该proposal包的ack数超过了一半<br>                        - outstandingProposals.remove(zxid); 1.移除proposal<br>                        - toBeApplied.add(p); 2.将proposal添加到toBeApplied队列<br>                            - 这个toBeApplied队列中的元素会在Leader.ToBeAppliedRequestProcessor.processRequest()中取出来 // 参见ToBeAppliedRequestProcessor.processRequest()逻辑<br>                        - commit(zxid); 3.创建Leader.COMMIT包并发给所有follower<br>                            - leader.commit()中 遍历所有LearnerHandler,将所有Leader.COMMIT包加入queuedPackets队列. 用于给followers发.<br>                                - ...<br>                                    - learnerHandler线程里,取出COMMIT包发给follower learnerHandler.sendPackets()里 会取queuedPackets队列中的所有packets并发送<br>                                        - ...<br>                                            - follower.processPacket()中,接收到COMMIT包后并处理.COMMIT包里只包含zxid信息,因为其他信息已经在之前的proposal包里包含了.  若是COMMIT包,调fzk.commit(qp.getZxid()); case Leader.COMMIT: fzk.commit(qp.getZxid()); break;<br>                                                - FollowerZookeeperServer.commit(long zxid)中 取出COMMIT包交由commitProcessor处理<br>                                                - long firstElementZxid = pendingTxns.element().zxid; 1.从待处理的事务队列pendingTxns中取出来第一个元素,判断它和commit包中的zxid是否一致<br>                                                - 2.从队列中移除后,交由follower的commitProcessor进行处理 Request request = pendingTxns.remove(); commitProcessor.commit(request);<br>                                                    - // 参见commitProcessor.commit(request);逻辑<br>                        - inform(p); 4.创建Leader.INFORM包,发送给所有observers<br>                            - 由于observer服务器未参加之前的提议投票, 因此observer服务器尚未保存任何关于该提议的消息, 所有在广播commit消息时,需要区别对待, leader会向其发送INFORM消息,该消息体重包含了当前提议的内容.<br>                        - zk.commitProcessor.commit(p.request);// commit<br>                            - 调用leader的commitProcessor.commit()方法<br></code></pre></td></tr></table></figure>

<h4 id="CommitProcessor"><a href="#CommitProcessor" class="headerlink" title="CommitProcessor"></a>CommitProcessor</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><code class="hljs plaintext">- CommitProcessor<br>    - 作用<br>        - 事务提交处理器. <br>        - 对于非事务请求,该处理器直接将其交给下一个处理器进行处理. <br>        - 对于事务请求,它会等待集群内 针对Proposal的投票 直到该Proposal可被提交. <br>        - 利用它,每个服务器都能很好的控制对事务请求的顺序处理. <br>        - 其实就是对于事务请求,commitProcessor会保证它这个事务请求必须经过proposal包和commit包之后,才会将它放入toProcess队列交给下个processor进行处理<br>    - 变量<br>        - queuedRequests<br>            - queuedRequests 中的请求是在proposalRequestProcessor.processRequest()中加入进来的. 这些请求当时还没有进行proposal和commit包的处理<br>        - committedRequests<br>            - committedRequests中的请求时在执行完proposal和commit包后加入进来的<br>        - toProcess<br>            - queuedRequests队列中 所有非事务请求添加到 toProcess队列,用于交给下个processor处理<br>        - nextPending<br>            - queuedRequests队列中 下一个等待处理的事务请求<br><br>    - commitProcessor.processRequest()逻辑<br>        - 请求入queuedRequests队列. leader 和 所有 follower 在 ProposalRequestProcessor 中 都会调用该方法.  queuedRequests 中的请求是在 proposalRequestProcessor.processRequest()中加入进来的.这些请求当时还没有进行 proposal 和 commit包的处理  queuedRequests.add(request);// 将请求 添加到 请求队列 notifyAll();<br><br>    - commitProcessor.commit(request)逻辑<br>        - 当leader完成了proposal过半,给followers发commit包之后,自己也会走commit逻辑. follower收到commit包也会走自己的commit逻辑.<br>        - 完成proposal和commit包的请求入committedRequests队列 committedRequests.add(request); notifyAll();<br><br>    - commitProcessor.run()逻辑<br>        - 1.依次调用toProcess队列中每个request的nextProcessor,并清空队列<br>            - // 参见Leader.ToBeAppliedRequestProcessor.processRequest() nextProcessor.processRequest(toProcess.get(i));<br>        - 2.queuedRequests队列已经取完了,或nextPending已经设置值了 (其实就是在queuedRequest队列中已经找到了一个需要处理的事务请求)<br>            - 此时若committedRequests为空(即还没收到要commit的请求), 线程wait(),跳出此次循环<br>            - 2.2 若有commit请求<br>                - 取出commit请求  Request r = committedRequests.remove(); 并和nextPending比较,二者应该一致. 赋值事务头,加入toProcess队列 toProcess.add(nextPending);<br>        - 3.只要nextPending有值,就不走4的逻辑<br>        - 4.遍历queuedRequests队列,从里面取出第一个事务请求给nextPending赋值<br></code></pre></td></tr></table></figure>

<h4 id="ToBeAppliedRequestProcessor"><a href="#ToBeAppliedRequestProcessor" class="headerlink" title="ToBeAppliedRequestProcessor"></a>ToBeAppliedRequestProcessor</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs plaintext">- ToBeAppliedRequestProcessor<br>    - 作用<br>        - 维护toBeApplied队列,专门存储那些已经被CommitProcessor处理过的可被提交的Proposal<br>        - 它将这些请求逐个交付给FinalRequestProcessor处理器进行处理,等待FinalRequestProcessor处理器处理完后,再将其从toBeApplied队列中移除. <br>        - 下个处理器必须是FinalRequestProcessor并且FinalRequestProcessor必须同步处理请求。<br>    - 变量<br>        - toBeApplied队列<br>            - 元素放入:leader接收到的对于该proposal包的ack数超过了一半时便会放入<br>            - 元素取出:ToBeAppliedRequestProcessor.processRequest()取出交给finalRequestProcessor进行处理<br><br>    - Leader.ToBeAppliedRequestProcessor.processRequest()<br>        - 取出请求,调next,并移除 next.processRequest(request); toBeApplied.remove();<br>            - // 参见FinalRequestProcessor.processRequest()逻辑<br></code></pre></td></tr></table></figure>

<h4 id="FinalRequestProcessor"><a href="#FinalRequestProcessor" class="headerlink" title="FinalRequestProcessor"></a>FinalRequestProcessor</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs plaintext">- FinalRequestProcessor<br>    - 作用<br>        - 通常是请求处理链的最后一个处理器。 <br>        - 创建客户端请求的响应;针对事务请求,它还会负责将事务应用到内存数据库中.<br>        <br>    - FinalRequestProcessor.processRequest()<br>        - 1.遍历zks.outstandingChanges(提交的事务请求),zxid比request.zxid小的请求都给干掉.<br>        - 2.若是事务请求应用到内存数据库 if (request.hdr != null)  rc = zks.processTxn(hdr, txn);<br>            - rc = getZKDatabase().processTxn(hdr, txn);<br>                - 事务写到内存  return dataTree.processTxn(hdr, txn);<br>        - zks.getZKDatabase().addCommittedProposal(request); 3.事务请求保存到 committedLog<br>        - 4.根据请求code,创建response响应客户端  rsp = new CreateResponse(rc.path); cnxn.sendResponse(hdr, rsp, &quot;response&quot;);<br>            - // 事务请求结束<br></code></pre></td></tr></table></figure>

<h4 id="FollowerRequestProcessor"><a href="#FollowerRequestProcessor" class="headerlink" title="FollowerRequestProcessor"></a>FollowerRequestProcessor</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs plaintext">- FollowerRequestProcessor<br>    - 它是follower的第一个请求处理器.用于识别当前请求是否是事务请求. <br>    - 若是事务请求,转发给leader服务器.leader在收到这个事务请求后,就会将其提交到请求处理器链,按照正常事务请求进行处理.<br></code></pre></td></tr></table></figure>
<link rel="stylesheet" href="https://fastly.jsdelivr.net/npm/markmap-toolbar@0.18.10/dist/style.css"><script src="https://fastly.jsdelivr.net/npm/d3@7"></script><script src="https://fastly.jsdelivr.net/npm/markmap-view@0.18.10"></script><script src="https://fastly.jsdelivr.net/npm/markmap-toolbar@0.18.10"></script>
<link rel="stylesheet" href="/css/markmap.css">

<script src="/js/markmap.js"></script>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta"><i class="fas fa-circle-user fa-fw"></i>文章作者: </span><span class="post-copyright-info"><a href="https://flyingzc.github.io">flyingzc</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta"><i class="fas fa-square-arrow-up-right fa-fw"></i>文章链接: </span><span class="post-copyright-info"><a href="https://flyingzc.github.io/articles/zk/zk05_processor.html">https://flyingzc.github.io/articles/zk/zk05_processor.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta"><i class="fas fa-circle-exclamation fa-fw"></i>版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来源 <a href="https://flyingzc.github.io" target="_blank">flyingzc's blog</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/Zookeeper/">Zookeeper</a></div><div class="post-share"><div class="social-share" data-image="/images/zc-icon.jpeg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><a class="pagination-related" href="/articles/zk/zk01_build.html" title="Zookeeper环境搭建"><div class="cover" style="background: var(--default-bg-color)"></div><div class="info text-center"><div class="info-1"><div class="info-item-1"><i class="far fa-calendar-alt fa-fw"></i> 2019-01-17</div><div class="info-item-2">Zookeeper环境搭建</div></div><div class="info-2"><div class="info-item-1">zk idea 代码阅读环境搭建采用最新的 zookeeper release 版本 3.4.13zk发行版下载地址 从 github 上 clone 该版本的代码. 1. ant 构建 zkbuild.xml 搜索 ant-eclipse-1.0.bin.tar.bz2, 1290行修改 12&lt;get src=&quot;http://ufpr.dl.sourceforge.net/project/ant-eclipse/ant-eclipse/1.0/ant-eclipse-1.0.bin.tar.bz2&quot;dest=&quot;$&#123;src.dir&#125;/java/ant-eclipse-1.0.bin.tar.bz2&quot; usetimestamp=&quot;false&quot; /&gt; 执行 ant eclipse 2. idea 导入这个 eclipse 项目即可File -&gt; New -&gt; import project from exist source -&gt; 选eclipse 将...</div></div></div></a><a class="pagination-related" href="/articles/zk/zk02_start.html" title="Zookeeper启动流程"><div class="cover" style="background: var(--default-bg-color)"></div><div class="info text-center"><div class="info-1"><div class="info-item-1"><i class="far fa-calendar-alt fa-fw"></i> 2019-01-18</div><div class="info-item-2">Zookeeper启动流程</div></div><div class="info-2"><div class="info-item-1">zk启动流程 启动类为 QuorumPeerMain 解析 zoo.cfg 配置 创建并启动 DatadirCleanupManager 用于清理过期 snapshot 和 txnlog. 创建 QuorumPeer 实例并启动该线程,用于完成选举. 根据 snapshot 和 txnlog 恢复 内存数据库 ZKDatabase.  12345678910111213141516171819202122232425262728293031323334353637383940- QuorumPeerMain.main()- 1.创建QuorumPeerMain对象- 2.初始化 运行 main.initializeAndRun(args)    - 0.创建QuorumPeerConfig对象    - 1.通过QuorumPeerConfig.parse(),解析配置文件         - 读取zoo.cfg配置到Properties中        - parseProperties()解析Properties配置到QuorumPeerConfig对象中    -...</div></div></div></a><a class="pagination-related" href="/articles/zk/zk03_vote.html" title="Zookeeper选举流程"><div class="cover" style="background: var(--default-bg-color)"></div><div class="info text-center"><div class="info-1"><div class="info-item-1"><i class="far fa-calendar-alt fa-fw"></i> 2019-02-18</div><div class="info-item-2">Zookeeper选举流程</div></div><div class="info-2"><div class="info-item-1">leader选举相关线程QuorumCnxManager : 管理者,包含发送 和 接收 队列.持有 listener. QuorumCnxManager.Listener : 监听 并 建立 server 之间的连接. FastLeaderElection.Messenger.SendWorker消息生产者.循环 从发送队列 queueSendMap 中取消息(出队)并发送出去.并将该消息存入 lastMessageSent 中. FastLeaderElection.Messenger.RecvWorker消息消费者.循环 接收线程从底层 Socket 收到报文后放到 recvQueue 队列中,等待 Messenger 调用 pollRecvQueue 方法获取消息. leader选举流程启动时选举选举算法的创建之前先创建 QuorumCnxManager,它通过 TCP 协议来进行 leader...</div></div></div></a><a class="pagination-related" href="/articles/zk/zk04_sync.html" title="Zookeeper数据同步流程"><div class="cover" style="background: var(--default-bg-color)"></div><div class="info text-center"><div class="info-1"><div class="info-item-1"><i class="far fa-calendar-alt fa-fw"></i> 2019-01-17</div><div class="info-item-2">Zookeeper数据同步流程</div></div><div class="info-2"><div class="info-item-1">zk选举完后数据同步流程Leader为每个Follower&#x2F;observer都建立一个TCP长连接. LearnerHandler,即learner服务器的管理者,负责follower&#x2F;observer服务器和leader服务器之间的一系列网络通信.包括数据同步,请求转发和Proposal提议的投票等. leader.lead();-&gt;leader 从磁盘中恢复数据和session列表Leader zk.loadData();-&gt;Leader 启动监听线程 LearnerCnxAcceptor, 等待新的followers的连接请求-&gt;follower 连接leaderFollower follower.followLeader();-&gt;LearnerCnxAcceptor 监听到follower的socket请求,为每个 follower 创建单独的 LearnerHandler 线程用于交互.-&gt;follower 发送 FOLLOWERINFO 包 给leader,包括新的zxid​和 sidFollower...</div></div></div></a><a class="pagination-related" href="/articles/zk/zk06_snapshot_txnlog.html" title="Zookeeper事务日志，快照"><div class="cover" style="background: var(--default-bg-color)"></div><div class="info text-center"><div class="info-1"><div class="info-item-1"><i class="far fa-calendar-alt fa-fw"></i> 2019-05-07</div><div class="info-item-2">Zookeeper事务日志，快照</div></div><div class="info-2"><div class="info-item-1">ZKDataBase结构ZKDataBase(zk内存数据库)    – sessionWithTimeouts(zk所有会话  会话超时时间记录器)    – DataTree存储    – 事务日志 ZKDatabase会定时向磁盘dump快照数据,在zk启动时通过磁盘上的事务日志 和 快照文件 恢复 一个完整的内存数据库 事务日志dataLogDir 文件大小都是64MB 文件名 log.xxxxxx为事务id : zxid, 且 为写入该事务文件第一条事务记录的zxid. zxid由两部分组成: 高32位 为 当前leader周期(epoch), 低32位 为 真正的操作序列号. LogFormatter 可以查看该文件 事务日志操作 滚动日志FileTxnLog.rollLog()将当前日志文件 滚动为新文件.其实就是将 logStream置为null,那么要写入日志时就会新创建一个日志文件用于写入.  写事务日志FileTxnLog.append(TxnHeader hdr, Record txn)   若logStream &#x3D;&#x3D; null,...</div></div></div></a><a class="pagination-related" href="/articles/zk/zk07_usage.html" title="Zookeeper应用"><div class="cover" style="background: var(--default-bg-color)"></div><div class="info text-center"><div class="info-1"><div class="info-item-1"><i class="far fa-calendar-alt fa-fw"></i> 2019-05-07</div><div class="info-item-2">Zookeeper应用</div></div><div class="info-2"><div class="info-item-1">dubbo中zk的应用123456789在zk中创建的节点路径dubbo    com.alibaba.demo.DemoService [服务名,service]        configurators        consumers [类型,type,生产者消费者]            ...        providers            ... [url]        routers     其中接口(service)下会有四个子节点providers, consumers, routers, configurators 其中dubbo、接口、providers都是持久化节点，只有url是临时节点。当会话消失(服务器断开与zookeeper的连接)，对应的临时节点会被删除。 dubbo-registry-zookeeper模块中, ZookeeperRegistry 类继承自 FailbackRegistry.构造方法中通过...</div></div></div></a></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info text-center"><div class="avatar-img"><img src="/images/zc-icon.jpeg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info-name">flyingzc</div><div class="author-info-description">不积跬步无以至千里<br/>不积小流无以成江海</div><div class="site-data"><a href="/archives/"><div class="headline">文章</div><div class="length-num">84</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">36</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">29</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/FlyingZC"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons"><a class="social-icon" href="https://github.com/FlyingZC" target="_blank" title="Github"><i class="fab fa-github" style="color: #24292e;"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">FlyingZC's Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#processors"><span class="toc-number">1.</span> <span class="toc-text">processors</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#processor%E9%93%BE%E5%AF%B9%E4%BA%8B%E5%8A%A1%E8%AF%B7%E6%B1%82%E7%9A%84%E5%A4%84%E7%90%86"><span class="toc-number">2.</span> <span class="toc-text">processor链对事务请求的处理</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#PrepRequestProcessor"><span class="toc-number">2.1.</span> <span class="toc-text">PrepRequestProcessor</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#ProposalRequestProcessor"><span class="toc-number">2.2.</span> <span class="toc-text">ProposalRequestProcessor</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#syncProcessor"><span class="toc-number">2.3.</span> <span class="toc-text">syncProcessor</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#SyncRequestProcessor"><span class="toc-number">2.4.</span> <span class="toc-text">SyncRequestProcessor</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#AckRequestProcessor"><span class="toc-number">2.5.</span> <span class="toc-text">AckRequestProcessor</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#SendAckRequestProcessor"><span class="toc-number">2.6.</span> <span class="toc-text">SendAckRequestProcessor</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#CommitProcessor"><span class="toc-number">2.7.</span> <span class="toc-text">CommitProcessor</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#ToBeAppliedRequestProcessor"><span class="toc-number">2.8.</span> <span class="toc-text">ToBeAppliedRequestProcessor</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#FinalRequestProcessor"><span class="toc-number">2.9.</span> <span class="toc-text">FinalRequestProcessor</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#FollowerRequestProcessor"><span class="toc-number">2.10.</span> <span class="toc-text">FollowerRequestProcessor</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/articles/ignite/ignite03-transaction-begin.html" title="Apache Ignite 开启事务执行流程">Apache Ignite 开启事务执行流程</a><time datetime="2025-10-10T16:00:00.000Z" title="发表于 2025-10-11 00:00:00">2025-10-11</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/articles/ignite/ignite02-transaction.html" title="Apache Ignite 分布式事务原理">Apache Ignite 分布式事务原理</a><time datetime="2025-09-17T16:00:00.000Z" title="发表于 2025-09-18 00:00:00">2025-09-18</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/articles/ignite/ignite01-build.html" title="Apache Ignite IDEA 环境搭建">Apache Ignite IDEA 环境搭建</a><time datetime="2025-09-10T16:00:00.000Z" title="发表于 2025-09-11 00:00:00">2025-09-11</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/articles/druid/druid01-resultset-leak.html" title="ShardingSphere JDBC 使用 Druid 连接池 ResultSet 内存泄露分析">ShardingSphere JDBC 使用 Druid 连接池 ResultSet 内存泄露分析</a><time datetime="2025-06-30T16:00:00.000Z" title="发表于 2025-07-01 00:00:00">2025-07-01</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/articles/jmeter/jmeter01-shardingsphere.html" title="Jmeter 压测 ShardingSphere">Jmeter 压测 ShardingSphere</a><time datetime="2025-06-30T16:00:00.000Z" title="发表于 2025-07-01 00:00:00">2025-07-01</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2025 By flyingzc</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="日间和夜间模式切换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>